package at.fhj.itm11.fotorater.service;

import java.util.List;
import java.util.logging.Logger;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;

import at.fhj.itm11.fotorater.data.CategoryRepository;
import at.fhj.itm11.fotorater.data.PhotoRepository;
import at.fhj.itm11.fotorater.model.Category;
import at.fhj.itm11.fotorater.model.Photo;

@Stateless
public class PhotoViewService {
	
	@Inject
	private Logger log;
	
	@Inject
	private PhotoRepository phoRepo;
	
	@Inject
	private CategoryRepository catRepo;
	
	@Inject
	private EntityManager em;
	
	public List<Photo> getPhotosByDate(int firstResult, int maxResult) {
		return phoRepo.findAllOrderedByUploadDate(firstResult, maxResult);
	}
	
	public List<Category> getCategoriesOrderedByName() {
		return catRepo.findAllOrderedByName();
	}
	
	public List<Photo> getPhotosByCategory(long categoryId, int firstResult, int maxResult) {
		Category category = catRepo.findById(categoryId);
		return phoRepo.findAllForCategory(category, firstResult, maxResult);
	}
	
	public List<Photo> getPhotosByLikes(int firstResult, int maxResult) {
		return phoRepo.findAllOrderedByLikes(firstResult, maxResult);
	}
	
	public List<Photo> getPhotosByDislikes(int firstResult, int maxResult) {
		return phoRepo.findAllOrderedByDislikes(firstResult, maxResult);
	}
}
